package com.xiaotu.storage;

import java.util.Date;

import org.springframework.stereotype.Component;

import com.xiaotu.common.util.Constants;
import com.xiaotu.common.util.DataRedisKeyUtils;
import com.xiaotu.common.util.SepratorUtil;
import com.xiaotu.storage.converter.AConverter;
import com.xiaotu.storage.converter.ConverterFactory;
import com.xiaotu.storage.model.CacheDataModel;

import net.sf.json.JSONObject;

/**
 * @类名 TVChangeStorageProcessor
 * @日期 2017年10月09日
 * @作者 王艳龙
 * @功能 电视局备案变更转储实现类
 */
@Component("TVChangeStorageProcessor")
public class TVChangeStorageProcessor extends AHSetStorageProcessor
{
    private static final String[] FIELD_ARR = new String[]{"tvName","oldtvName", "sets","oldsets", "producecompany", "oldproducecompany", "subject","type","timestamp"};

    private static final String[] CONVERT_ARR = new String[]{AConverter.STRING_CONVERT, AConverter.STRING_CONVERT,
            AConverter.STRING_CONVERT, AConverter.STRING_CONVERT, AConverter.STRING_CONVERT,
            AConverter.STRING_CONVERT, AConverter.STRING_CONVERT, AConverter.INTEGER_CONVERT,AConverter.TIMESTAMP_CONVERT};

    private static final boolean[] THROW_ARR = new boolean[]{true, true, true, true, true,true,true,true,true};

    @Override
    protected String getRedisKey(Date date)
    {
        return DataRedisKeyUtils.getKey(Constants.DataRedisKey.TV_Change_YYYYMMDD, date);
    }

    @Override
    public String process(JSONObject target, CacheDataModel cacheData, Date date)
    {
        //this.validateAllNotEmpty(target, FIELD_ARR);
        target.put(FIELD_ARR[4], target.getString(FIELD_ARR[4]).replaceAll(SepratorUtil.SEP_SLASH_EN, SepratorUtil
                .SEP_CROSS_EN));
        return this.list2CSVLine(ConverterFactory.convert(target, FIELD_ARR, CONVERT_ARR, THROW_ARR));
    }

    @Override
    public String getDataType()
    {
        return Constants.PageDataType.SEARCH_LIST;
    }

    @Override
    public String getTaskType()
    {
        return Constants.SpiderTaskType.TV_CHANGE_DATA;
    }
}
